package com.analyse.stock.controller;

import com.analyse.stock.service.*;
import com.analyse.stock.vo.ResultUtils;
import com.analyse.stock.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/base")
public class BaseInfoPullController {

    @Autowired
    private IStockInfo stockInfo;

    @Autowired
    private IStockExchange stockExchange;

    @Autowired
    private ICountryInfo countryInfo;

    @Autowired
    private IIndexInfo indexInfo;

    @Autowired
    private IBoardCategory boardCategory;

    @Autowired
    private IBoardIndexDaily boardDaily;

    /**
     * 获取所有的股票，根据国家，CHN
     */
    @GetMapping("/stock/pull/{countryCode}")
    public ResultVo<Integer> pullStockList(@PathVariable String countryCode) {
        Integer num = stockInfo.pullStockList(countryCode);
        return ResultUtils.ok(num);
    }

    /**
     * 更新所有股票的 财务数据和板块数据
     */
    @GetMapping("/stock/update")
    public ResultVo<Integer> update(@RequestParam(name="code") String stockCodes) {
        Integer num = stockInfo.update(stockCodes);
        return ResultUtils.ok(num);
    }

    /**
     * 获取所有的交易所，根据国家，CHN
     */
    @GetMapping("/exchange/pull")
    public ResultVo<Integer> pullExchange(@RequestParam(name = "code") String countryCode) {
        Integer num = stockExchange.getAllStockExchange(countryCode);
        return ResultUtils.ok(num);
    }

    /**
     * 拉取 国家/地区清单
     */
    @GetMapping("/country/pull")
    public ResultVo<Integer> pullCountry() {
        Integer num = countryInfo.pullCountryList();
        return ResultUtils.ok(num);
    }

    /**
     * 拉取 指数清单
     */
    @GetMapping("/index/pull")
    public ResultVo<Integer> pullIndex(@RequestParam(name = "code") String countryCode) {
        //Integer num = indexInfo.pullIndexList(countryCodes);
        Integer num =  indexInfo.pullIndexListByEasyMoney(countryCode);
        return ResultUtils.ok(num);
    }

    /**
      * 拉取板块分类 (地域板块，行业板块，概念板块)
     */
    @GetMapping("/board/pull")
    public ResultVo<Integer> pullBoard(@RequestParam(name = "code") String boards) {
        Integer num = boardCategory.pullBoardCategoryList(boards);
        return ResultUtils.ok(num);
    }

    /**
     * 拉取板块最新的涨跌，资金流向数据
     */
    @GetMapping("/boardDaily/pull")
    public ResultVo<Integer> pullBoardDaily(@RequestParam(name = "code") String boards) {
        Integer num = boardDaily.pullBoardDailyList(boards);
        return ResultUtils.ok(num);
    }

    /**
     * 拉取指数最新的涨跌，资金流向数据
     */
    @GetMapping("/indexDaily/pull")
    public ResultVo<Integer> pullIndexDaily(@RequestParam(name = "code") String indexCodes) {
        Integer num = boardDaily.pullIndexDailyList(indexCodes);
        return ResultUtils.ok(num);
    }
}
